package com.example.barcodeapp.ui.huodong;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.adapter.YouHuiJunAdapter;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.own.bean.HuoDongBean;

import java.util.List;

public class AdapterZuiXin extends RecyclerView.Adapter<AdapterZuiXin.ViewHolder> {
    Context context;
    private List<HuoDongBean.DataEntity> list;

    public AdapterZuiXin(Context context, List<HuoDongBean.DataEntity> list) {
        this.context = context;
        this.list = list;
    }

    public AdapterZuiXin(Context context) {
        this.context = context;
    }
    private AdapterZuiXin.IClick callback;
    public void setClick(AdapterZuiXin.IClick cb){
        callback = cb;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_huoodong_zuixin, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });

        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getHuodong_image()).into( holder.zuixinImg);
        holder.zuixinTvName.setText(list.get(position).getHuodong_name());
        holder.zuixinTvNeirong.setText(list.get(position).getHuodong_date_desc());
        holder.zuixinTvNeirong.setText(list.get(position).getHuodong_date_desc());
        holder.zuixinJiage.setText(list.get(position).getHuodong_price()+"￥");



    }

    @Override
    public int getItemCount() {
        return 2;
    }



    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView zuixinImg;
        private TextView zuixinTvName;
        private TextView zuixinTvNeirong;
        private TextView zuixinJiage;

        public ViewHolder(@NonNull View itemView) {

            super(itemView);
            zuixinImg = (ImageView) itemView.findViewById(R.id.zuixin_img);
            zuixinTvName = (TextView) itemView.findViewById(R.id.zuixin_tv_name);
            zuixinTvNeirong = (TextView) itemView.findViewById(R.id.zuixin_tv_neirong);
            zuixinJiage = (TextView) itemView.findViewById(R.id.zuixin_jiage);
        }
    }


    public interface IClick{
        void click(int pos);
    }

}
